﻿using RuneMasterWin8.Core;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Windows.ApplicationModel;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.Graphics.Display;
using Windows.System;
using Windows.UI.Popups;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;

// “基本页”项模板在 http://go.microsoft.com/fwlink/?LinkId=234237 上有介绍

namespace RuneMasterWin8.Pages
{
    /// <summary>
    /// 基本页，提供大多数应用程序通用的特性。
    /// </summary>
    public sealed partial class GiftPage : RuneMasterWin8.Common.LayoutAwarePage
    {
        bool isCommented = false;

        public GiftPage()
        {
            this.InitializeComponent();

            DisplayProperties.AutoRotationPreferences = DisplayOrientations.Landscape | DisplayOrientations.LandscapeFlipped;
        }

        /// <summary>
        /// 使用在导航过程中传递的内容填充页。在从以前的会话
        /// 重新创建页时，也会提供任何已保存状态。
        /// </summary>
        /// <param name="navigationParameter">最初请求此页时传递给
        /// <see cref="Frame.Navigate(Type, Object)"/> 的参数值。
        /// </param>
        /// <param name="pageState">此页在以前会话期间保留的状态
        /// 字典。首次访问页面时为 null。</param>
        protected override void LoadState(Object navigationParameter, Dictionary<String, Object> pageState)
        {
        }

        /// <summary>
        /// 保留与此页关联的状态，以防挂起应用程序或
        /// 从导航缓存中放弃此页。值必须符合
        /// <see cref="SuspensionManager.SessionState"/> 的序列化要求。
        /// </summary>
        /// <param name="pageState">要使用可序列化状态填充的空字典。</param>
        protected async override void SaveState(Dictionary<String, Object> pageState)
        {
            if (isCommented)
            {
                StageManager.Instance.IsDoNewUserTask = true;
                StageManager.Instance.IsCommented = true;
                //增加金币
                StageManager.Instance.TotalG += 10000;
                MessageDialog md = new MessageDialog("恭喜！获得10000个游戏金币，快去使用强大的道具吧！");
                await md.ShowAsync();
            }
        }

        private async void btnGetCoin_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e)
        {
            this.btnGetCoin.IsEnabled = false;
            Uri uri = new Uri("ms-windows-store:REVIEW?PFN=" + Package.Current.Id.FamilyName);
            await Launcher.LaunchUriAsync(uri);
            //await Launcher.LaunchUriAsync(new Uri("ms-windows-store:REVIEW?PFN=5447777Studio.19166352F0D83"));
            DispatcherTimer timer = new DispatcherTimer();
            timer.Interval = TimeSpan.FromSeconds(3);
            timer.Tick += (object ss, object ee) =>
            {
                isCommented = true;
                timer.Stop();
            };
            timer.Start();
        }
    }
}
